<?php
/**
 * Created by zqk.
 * User: zqk
 * Date: 2018/8/30
 * Time: 9:32
 */

namespace Pm\Controllers;

use Modules\Power;
use Helpers\Template;
use Helpers\Main;
use Helpers\Assets;
use Admin\Models\pm\XhpmProjectTask;
use Admin\Models\pm\XhpmTaskMember;
use Helpers\User;
use Admin\Models\hrm\XhhrmStaff;
use Admin\Models\hrm\XhhrmDepart;

class TaskstatsController extends ControllerBase
{
    private static $task_levels = [
        1 => '普通',
        2 => '重要',
        3 => '紧急',
    ];

    private static $task_status = [
        1 => '待处理',
        2 => '进行中',
        3 => '已完成',
        4 => '已关闭',
    ];

    /**
     * 任务统计列表
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180830 10:36:16
     */
    public function indexAction()
    {
        if (!Power::exist('Bpm_Project_Task_stats')) {
            return $this->sendViewError('无任务统计权限');
        }
        $this->view->pick('taskstats/taskStatsList');
        Main::showNavPosition();
        Assets::importMainJs('assets/xh/xhDatagrid.js');
        Assets::easyUI();
        Assets::importJs('js/myMain.js');
        Assets::importJs('js/taskstats/statsList.js');
        Assets::datetimePicker();
        $taskSearchArr = [];
        $taskSearchArr[] = ['class' => 'form-date', 'type' => 'text', 'id' => 'startTime'];
        $taskSearchArr[] = ['class' => 'form-date', 'type' => 'text', 'id' => 'endTime', 'label' => ' ~ '];
        $taskSearchArr[] = ['type' => 'text', 'id' => 'staffName', 'label' => ' 姓名: '];
        $taskSearchArr[] = ['type' => 'button', 'id' => 'bt_list_search', 'text' => '查找', 'icon' => 'fa-search', 'style' => 'margin-left:10px'];
        $this->view->setVars([
            'statsList' => Template::createList('statsList', 'statsList', ['searchToolbar' => Template::createSearchToolBar($taskSearchArr),]),
        ]);
    }

    /**
     * 获取部门列表
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180412
     */
    public function getDepartmentsAction()
    {
        try {
            $deps = XhhrmDepart::find([
                'columns' => 'iDepId,sDepName',
                'conditions' => 'bDelete = 0 And iParentId = 0'
            ])->toArray();
            foreach ($deps as $k => $dep) {
                $depId = $dep['iDepId'];
                $children = $this->getDepChildren($depId);
                if (!empty($children)) {
                    $deps[$k]['iconCls'] = 'fa-file-folder';
                    $deps[$k]['children'] = $children;
                    $deps[$k]['state'] = "closed";
                } else {
                    $deps[$k]['iconCls'] = 'fa-file-text';
                }
            }
            return $this->sendJsonResponse($deps);
        } catch (\Exception $exception) {
            return $this->sendErrorResponse(500, '获取失败！', $exception->getMessage());

        }
    }

    /**
     * 获取部门子部门
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180523
     */
    private function getDepChildren($id)
    {
        $deps = XhhrmDepart::find([
            'columns' => 'iDepId,sDepName',
            'conditions' => 'bDelete = 0 And iParentId = ' . $id,
        ])->toArray();
        foreach ($deps as $k => $dep) {
            $depId = $dep['iDepId'];
            $children = $this->getDepChildren($depId);
            if (!empty($children)) {
                $deps[$k]['iconCls'] = 'fa-file-folder';
                $deps[$k]['children'] = $children;
                $deps[$k]['state'] = "closed";
            } else {
                $deps[$k]['iconCls'] = 'fa-file-text';
            }
        }
        return $deps;
    }

    /**
     * 获取任务统计列表
     *
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180830
     */
    public function getTaskStatsAction()
    {
        $iDepId = $this->request->getPost('iDepId', 'int', 0);
        $sStaffName = $this->request->getPost('sStaffName');
        $fromAt = $this->request->getPost('startTime');
        $endAt = $this->request->getPost('endTime');
        $days = 0;
        $condition = "bDelete = 0 and iUserId > 0";
        $condition .= $iDepId ? " AND sDepIds like '%$iDepId%'" : '';
        $condition .= $sStaffName ? " AND sStaffName like '%$sStaffName%'" : '';
        $condition1 = 'bDelete = 0';
        if ($endAt && $endAt && $endAt >= $fromAt) {
            $endAt = strtotime($endAt) + 24 * 60 * 60;
            $endAt = date('Y-m-d', $endAt);
            $days = $this->getDays($fromAt, $endAt);
            $endAt = $endAt ? date_format(date_create($endAt), "Y-m-d H:i:s") : '';
            $fromAt = $fromAt ? date_format(date_create($fromAt), "Y-m-d H:i:s") : '';
            $condition1 .= $fromAt ? ' AND tCreateDate >= "' . $fromAt .'"' : '';
            $condition1 .= $endAt ? ' AND tCreateDate <= "' . $endAt .'"' : '';
        }
        try {
            $builder = $this->modelsManager->createBuilder()
                ->columns("sStaffName,iUserId")
                ->addFrom('Admin\Models\hrm\XhhrmStaff')
                ->where($condition);
            $data = Main::runBuilderPaginator($builder, true);
            foreach ($data['rows'] as $key => $value) {
                $userId = $value['iUserId'];
                $iTaskIds = $this->modelsManager->createBuilder()
                    ->columns("iTaskId")
                    ->addFrom('Admin\Models\pm\XhpmTaskMember')
                    ->where("bDelete = 0 AND bIfExecutor = 1 AND iUserId = $userId")
                    ->groupBy('iTaskId')
                    ->getQuery()
                    ->execute()
                    ->toArray();
                $iTaskIds = array_column($iTaskIds, 'iTaskId');
                $sumTasks = $this->modelsManager->createBuilder()
                    ->columns("iTaskId")
                    ->addFrom('Admin\Models\pm\XhpmProjectTask')
                    ->where($condition1)
                    ->inWhere('iTaskId', $iTaskIds)
                    ->groupBy('iTaskId')
                    ->getQuery()
                    ->execute()
                    ->count();
                $data['rows'][$key]['sumTasks'] = $sumTasks;
                $finTasks = $this->modelsManager->createBuilder()
                    ->columns("iTaskId")
                    ->addFrom('Admin\Models\pm\XhpmProjectTask')
                    ->where($condition1 . " AND iTaskStatus = 3")
                    ->inWhere('iTaskId', $iTaskIds)
                    ->groupBy('iTaskId')
                    ->getQuery()
                    ->execute()
                    ->count();
                $data['rows'][$key]['finTasks'] = $finTasks;
                $expectTime = $this->modelsManager->createBuilder()
                    ->columns("SUM(dTaskTime) as expect")
                    ->addFrom('Admin\Models\pm\XhpmProjectTask')
                    ->where($condition1 . " AND iTaskStatus = 3")
                    ->inWhere('iTaskId', $iTaskIds)
                    ->getQuery()
                    ->execute()
                    ->toArray();
                $expectTime = $expectTime ? $expectTime[0]['expect'] : 0;
                $data['rows'][$key]['expectTime'] = $expectTime;
                $realTime = $this->modelsManager->createBuilder()
                    ->columns("SUM(dRealTaskTime) as realTime")
                    ->addFrom('Admin\Models\pm\XhpmProjectTask')
                    ->where($condition1 . " AND iTaskStatus = 3")
                    ->inWhere('iTaskId', $iTaskIds)
                    ->getQuery()
                    ->execute()
                    ->toArray();
                $realTime = $realTime ? $realTime[0]['realTime'] : 0;
                $data['rows'][$key]['realTime'] = $realTime;
                if ($finTasks && $sumTasks && ($sumTasks >= $finTasks)) {
                    $finPercent = $this->getFinPercent($finTasks, $sumTasks);
                    $data['rows'][$key]['finPercent'] = $finPercent;
                }
                if ($days) {
                    $data['rows'][$key]['normalTime'] = $days * 7;
                }
            }
            return $this->sendJsonResponse($data);
        } catch (\Exception $exception) {
            return $this->sendErrorResponse(500, '获取失败！', $exception->getMessage());
        }
    }

    /**
     * 获取时间段内工作日数
     *
     * @param $fromAt
     * @param $endAt
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180830
     */
    private function getDays($fromAt, $endAt)
    {
        $date1 = strtotime($fromAt);
        $date2 = strtotime($endAt);
        $delta = ($date2 - $date1) / (60 * 60 * 24);
        $weekEnds = 0;
        for ($i = 0; $i < $delta; $i++) {
            if (date('w', $date1) == 0 || date('w', $date1) == 6) {
                $weekEnds++;
            }
            $date1 += 60 * 60 * 24;
        }
        return $delta - $weekEnds;
    }

    /**
     * 任务列表
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180418
     */
    public function taskListAction()
    {
        if (!Power::exist('Bpm_Project_Task')) {
            return $this->sendViewError('权限不足', '无任务权限');
        }
        $this->view->pick('taskstats/taskList');
        $members = $this->modelsManager->createBuilder()
            ->columns("m.iUserId,u.sStaffName")
            ->addFrom('Admin\Models\pm\XhpmProjectMember', 'm')
            ->leftjoin('Admin\Models\hrm\XhhrmStaff', 'm.iUserId = u.iUserId', 'u')
            ->where('m.bDelete = 0')
            ->groupBy('m.iUserId')
            ->getQuery()
            ->execute()
            ->toArray();
        $members = array_column($members, 'sStaffName', 'iUserId');
        $this->di->get('assets')
            ->addCss('assets/sweetalert2/sweetalert2.min.css')
            ->addJs('assets/sweetalert2/sweetalert2.min.js');
        Main::showNavPosition();
        Assets::importMainJs('assets/xh/xhDatagrid.js');
        Assets::easyUI();
        Assets::importMainJs('assets/xh/xhTop.js');
        Assets::importMainJs('assets/easyui/datagrid-detailview.js');
        Assets::importJs('js/myMain.js');
        Assets::importJs('js/taskstats/taskList.js');
        Assets::datetimePicker();
        $taskSearchArr = [];
        $taskSearchArr[] = ['class' => 'form-date', 'type' => 'text', 'id' => 'startTime'];
        $taskSearchArr[] = ['class' => 'form-date', 'type' => 'text', 'id' => 'endTime', 'label' => ' ~ '];
        $taskSearchArr[] = [
            'label' => ' 任务等级 : ',
            'type' => 'select',
            'id' => 'taskLevel',
            'data' => ['' => '全部'] + self::$task_levels,
            'style' => 'margin-left:10px;width:80px;'
        ];
        $taskSearchArr[] = [
            'label' => ' 任务状态 : ',
            'type' => 'select',
            'id' => 'taskStatus',
            'data' => ['' => '全部'] + self::$task_status,
            'style' => 'margin-left:10px;width:80px;'
        ];
        $taskSearchArr[] = [
            'label' => ' 执行人 : ',
            'type' => 'select',
            'id' => 'memberid',
            'data' => ['' => '全部'] + $members,
            'style' => 'margin-left:10px;width:80px;'
        ];
        $taskSearchArr[] = [
            'type' => 'button',
            'id' => 'bt_list_search',
            'text' => '查找 ',
            'icon' => 'fa-search',
            'style' => 'margin-left:10px'
        ];
        $buttonArr = [];
        $buttonArr[] = [
            'plain' => 'true',
            'id' => 'editTask',
            'text' => '编辑',
            'icon' => 'fa-pencil',
        ];
        $buttonArr[] = [
            'plain' => 'true',
            'id' => 'delTask',
            'text' => '删除',
            'icon' => 'fa-remove',
        ];
        $buttonArr[] = [
            'plain' => 'true',
            'id' => 'linkTask',
            'text' => '关联任务',
            'icon' => 'fa-link',
        ];
        $buttonArr[] = [
            'plain' => 'true',
            'id' => 'changeStatus',
            'class' => 'menubutton',
            'text' => '状态',
            'icon' => 'fa-bars',
        ];
        $this->view->setVars([
            'taskStatus' => self::$task_status,
            'taskLevels' => self::$task_levels,
            'members' => $members,
            'taskEdit' => Power::exist('Bpm_Project_Task_Edit'),
            'taskDel' => Power::exist('Bpm_Project_Task_Del'),
            'taskList' => Template::createList('taskList', 'taskList', [
                'searchToolbar' => Template::createSearchToolBar($taskSearchArr, true),
                'buttonToolbar' => Template::createButtonToolBar($buttonArr),
            ]),
        ]);
    }

    /**
     * 获取任务列表
     *
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180921
     */
    public function getTaskAction()
    {
        try {
            if (!Power::exist('Bpm_Project_Task')) {
                return $this->sendErrorResponse('500', '权限不足', '无任务权限');
            }
            $status = $this->request->getPost('status', 'int'); //根据任务状态筛选
            $level = $this->request->getPost('level', 'int'); //根据任务等级筛选
            $userId = $this->request->getPost('userid', 'int'); //根据用户id
            $fromAt = $this->request->getPost('start');
            $endAt = $this->request->getPost('end');
            $condition = " t.bDelete = 0 AND t.iParentId = 0";
            $condition1 = " bDelete = 0 AND iParentId = :iParentId: ";
            $condition .= $status && in_array($status, [1, 2, 3, 4]) ? " AND t.iTaskStatus = $status " : "";
            $condition .= $level && in_array($level, [1, 2, 3]) ? " AND t.iLevel = $level " : '';
            if ($endAt && $endAt && $endAt >= $fromAt) {
                $fromAt = $fromAt ? date_format(date_create($fromAt), "Y-m-d H:i:s") : '';
                $endAt = $endAt ? date_format(date_create($endAt), "Y-m-d H:i:s") : '';
                $condition .=  ' AND t.tCreateDate between "' . $fromAt . '" and "'.$endAt.'"';
            }
            if ($userId) {//执行人
                $params = array(
                    'columns' => 'iTaskId',
                    'conditions' => "bIfExecutor=1 AND bDelete=:bDelete: AND iUserId=:iUserId: ",
                    'bind' => array('iUserId' => $userId, 'bDelete' => 0),
                );
                $taskIds = XhpmTaskMember::find($params)->toArray();
                $intaskIds = array_column($taskIds, 'iTaskId');
                $builder = $this->modelsManager->createBuilder()
                    ->columns("t.sRelatedId,u1.sStaffName as chargeName,u.sStaffName,t.bChecked,t.iTaskId,
                    t.sTaskName,t.dTaskTime,t.iParentId,t.sTaskContent,t.iLevel,t.iTaskStatus,t.iProcess,t.sRemarks,
                    t.tFromAt,t.tEndAt,t.tStartedAt,t.tFinishedAt,t.tCreateDate,t.tLastModifyDate,t.dRealTaskTime")
                    ->addFrom('Admin\Models\pm\XhpmProjectTask', 't')
                    ->leftjoin('Admin\Models\pm\XhpmTaskMember', 'm.iTaskId=t.iTaskId AND m.bIfExecutor =1 AND m.bDelete = 0', 'm')
                    ->leftjoin('Admin\Models\pm\XhpmTaskMember', 'm.iTaskId=m1.iTaskId AND m1.bCharge =1 AND m1.bDelete = 0', 'm1')
                    ->leftjoin('Admin\Models\hrm\XhhrmStaff', 'm.iUserId = u.iUserId', 'u')
                    ->leftjoin('Admin\Models\hrm\XhhrmStaff', 'm1.iUserId = u1.iUserId', 'u1')
                    ->where($condition)
                    ->inwhere('t.iTaskId', $intaskIds)
                    ->orderBy("t.iTaskId desc");
            } else {
                $builder = $this->modelsManager->createBuilder()
                    ->columns("t.sRelatedId,u1.sStaffName as chargeName ,u.sStaffName,t.bChecked,t.iTaskId,
                    t.sTaskName,t.dTaskTime,t.iParentId,t.sTaskContent,t.iLevel,t.iProcess,t.iTaskStatus,t.sRemarks,
                    t.tFromAt,t.tEndAt,t.tStartedAt,t.tFinishedAt,t.tCreateDate,t.tLastModifyDate,t.dRealTaskTime")
                    ->addFrom('Admin\Models\pm\XhpmProjectTask', 't')
                    ->leftjoin('Admin\Models\pm\XhpmTaskMember', 'm.iTaskId=t.iTaskId AND m.bIfExecutor =1 AND m.bDelete = 0', 'm')
                    ->leftjoin('Admin\Models\pm\XhpmTaskMember', 'm.iTaskId=m1.iTaskId AND m1.bCharge =1 AND m1.bDelete = 0', 'm1')
                    ->leftjoin('Admin\Models\hrm\XhhrmStaff', 'm.iUserId = u.iUserId', 'u')
                    ->leftjoin('Admin\Models\hrm\XhhrmStaff', 'm1.iUserId = u1.iUserId', 'u1')
                    ->where($condition)
                    ->orderBy("t.iTaskId desc");
            }
            $data = Main::runBuilderPages($builder, true);
            foreach ($data['rows'] as $key => $value) {
                $parameters = array(
                    'columns' => 'iTaskId',
                    'conditions' => $condition1,
                    'bind' => array('iParentId' => $value['iTaskId']),
                );
                $objs = XhpmProjectTask::find($parameters)->toArray();
                $data['rows'][$key]['state'] = empty($objs) ? '' : "closed";
                $data['rows'][$key]['iconCls'] = empty($objs) ? 'fa fa-file-text' : 'fa fa-folder';
                $children = $this->getTaskChildren($value['iTaskId']);
                $data['rows'][$key]['children'] = $children;
                //任务关联任务
                $relatedIds = explode(',', $data['rows'][$key]['sRelatedId']);
                $expandContent = $this->getExpandDatas($relatedIds);
                if ($expandContent) {
                    $ifExpand = $this->getIfExpand(1);
                    $data['rows'][$key]['ifExpand'] = $ifExpand;
                }
                $data['rows'][$key]['expandContent'] = $expandContent;
                //任务进度
                $process = $data['rows'][$key]['iProcess'];
                $processContent = $this->getProcess($process);
                $data['rows'][$key]['iProcess'] = $processContent;
                //任务等级
                $level = $data['rows'][$key]['iLevel'];
                $levelContent = $this->getLevel($level);
                $data['rows'][$key]['iLevel'] = $levelContent;
                //任务状态
                $status = $data['rows'][$key]['iTaskStatus'];
                $statusContent = $this->getStatus($status);
                $data['rows'][$key]['iTaskStatus'] = $statusContent;
                //是否审核
                $bChecked = $data['rows'][$key]['bChecked'];
                $checkedContent = $this->getChecked($bChecked);
                $data['rows'][$key]['bChecked'] = $checkedContent;

            }
            return $this->sendJsonResponse($data);
        } catch (\Exception $exception) {
            return $this->sendErrorResponse(500, '获取失败！', $exception->getMessage());
        }
    }

    /**
     * 获取taskchildren
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180614
     */
    private function getTaskChildren($iTaskId)
    {
        $condition = "t.bDelete=0 AND t.iParentId = :iParentId: ";
        $condition1 = "bDelete=0 AND iParentId = :iParentId: ";
        $param = array('iParentId' => $iTaskId);
        $data = $this->modelsManager->createBuilder()
            ->columns("t.sRelatedId,u1.sStaffName as chargeName,u.sStaffName,t.bChecked,t.iTaskId,t.sTaskName,
            t.dTaskTime,t.iParentId,t.sTaskContent,t.iProcess,t.iLevel,t.iTaskStatus,t.sRemarks,t.tFromAt,t.tEndAt,
            t.tStartedAt,t.tFinishedAt,t.tCreateDate,t.tLastModifyDate,t.dRealTaskTime")
            ->addFrom('Admin\Models\pm\XhpmProjectTask', 't')
            ->leftjoin('Admin\Models\pm\XhpmTaskMember', 'm.iTaskId=t.iTaskId AND m.bIfExecutor =1 AND m.bDelete = 0', 'm')
            ->leftjoin('Admin\Models\pm\XhpmTaskMember', 'm.iTaskId=m1.iTaskId AND m1.bCharge =1 AND m1.bDelete = 0', 'm1')
            ->leftjoin('Admin\Models\hrm\XhhrmStaff', 'm.iUserId = u.iUserId', 'u')
            ->leftjoin('Admin\Models\hrm\XhhrmStaff', 'm1.iUserId = u1.iUserId', 'u1')
            ->where($condition, $param)
            ->orderBy("t.iTaskId desc")
            ->getQuery()
            ->execute()
            ->toArray();
        foreach ($data as $k => $v) {
            $parameters = array(
                'columns' => 'iTaskId',
                'conditions' => $condition1,
                'bind' => array('iParentId' => $v['iTaskId']),
            );
            $objs = XhpmProjectTask::find($parameters)->toArray();
            if (!empty($objs)) {
                $data[$k]['state'] = "closed";
                $data[$k]['iconCls'] = 'fa fa-folder';
                $data[$k]['children'] = $this->getTaskChildren($v['iTaskId']);
            } else {
                $data[$k]['iconCls'] = 'fa fa-file-text';
            }

            //任务关联任务
            $relatedIds = explode(',', $data[$k]['sRelatedId']);
            $expandContent = $this->getExpandDatas($relatedIds);
            if ($expandContent) {
                $ifExpand = $this->getIfExpand(1);
                $data[$k]['ifExpand'] = $ifExpand;
            }
            $data[$k]['expandContent'] = $expandContent;
            //任务进度
            $process = $data[$k]['iProcess'];
            $processContent = $this->getProcess($process);
            $data[$k]['iProcess'] = $processContent;
            //任务等级
            $level = $data[$k]['iLevel'];
            $levelContent = $this->getLevel($level);
            $data[$k]['iLevel'] = $levelContent;
            //任务状态
            $status = $data[$k]['iTaskStatus'];
            $statusContent = $this->getStatus($status);
            $data[$k]['iTaskStatus'] = $statusContent;
            //是否审核
            $bChecked = $data[$k]['bChecked'];
            $checkedContent = $this->getChecked($bChecked);
            $data[$k]['bChecked'] = $checkedContent;
        }
        return $data;
    }

    /**
     * 获取关联任务信息
     *
     * @param $tIds
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180808
     */
    private function getExpandDatas($tIds)
    {
        $datas = $this->modelsManager->createBuilder()
            ->columns("t.sTaskName,t.iTaskStatus,s.sStaffName,t.iProcess")
            ->addFrom('Admin\Models\pm\XhpmProjectTask', 't')
            ->leftjoin('Admin\Models\pm\XhpmTaskMember', 'm.iTaskId=t.iTaskId AND m.bIfExecutor = 1 AND m.bDelete = 0', 'm')
            ->leftjoin('Admin\Models\hrm\XhhrmStaff', 'm.iUserId = s.iUserId', 's')
            ->where("t.bDelete = 0")
            ->inwhere('t.iTaskId', $tIds)
            ->getQuery()
            ->execute()
            ->toArray();
        return $datas;
    }

    /**
     * 获取任务完成百分比进度条html字符串
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180906
     */
    private function getFinPercent($finTasks, $sumTasks)
    {
        $percent = intval($finTasks) / intval($sumTasks);
        $percent = intval(sprintf("%.2f", $percent) * 100);
        $htmlstr = "<div  class='easyui-progressbar progressbar'  style='width: 100px;margin-left: 1px; height: 22px;'>
        <div class='progressbar-text' style='width: 100px; height: 20px; line-height: 20px;'>" . $percent .
            "%</div><div class='progressbar-value' style='width:" . $percent .
            "%;background-color: #428bca; color: #FFFFFF; height: 20px; line-height: 20px;'>
        <div class='progressbar-text' style='width: 100px;background-color: #428bca; 
        color: #FFFFFF; height: 20px; line-height: 20px;'>" . $percent . '%</div></div>';
        return $htmlstr;
    }

    /**
     * 获取任务完成百分比进度条html字符串
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by zqk 20180906
     */
    private function getProcess($process)
    {
        $htmlstr = '<div  class="easyui-progressbar progressbar"  style="width: 100px; height: 22px;">'
            . '<div class="progressbar-text" style="width: 100px; height: 20px; line-height: 20px;">' . $process .
            '%</div> '
            . '	<div class="progressbar-value" style="width:' . $process . '%; height: 20px; line-height: 20px;">'
            . '<div class="progressbar-text" style="width: 100px; height: 20px; line-height: 20px;">' . $process .
            '%</div>'
            . '</div>';
        return $htmlstr;
    }

    /**
     * 任务是否展开
     *
     * @param $ifExpand
     *
     * @return string
     *
     * create by zqk 20180925
     */
    private function getIfExpand($ifExpand)
    {
        if ($ifExpand) {
            $str = '<div style="text-align:center;height:16px;" class="datagrid-cell ifExpand undefined">'
                .'<span class="datagrid-row-expander datagrid-row-expand" style="display:inline-block;width:16px;height:16px;cursor:pointer;"></span></div>';
        } else {
            $str = '<div style="text-align:center;height:16px;" class="datagrid-cell ifExpand undefined">'
                .'<span class="datagrid-row-expander datagrid-row-expand" style="display:none;width:16px;height:16px;cursor:pointer;"></span></div>';
        }
        return $str;
    }

    /**
     * 任务等级
     *
     * @param $value
     *
     * @return string
     *
     * create by zqk 20180925
     */
    private function getLevel($value)
    {
        $str = '';
        if ($value == '1') {
            $str = '<div style = "background-color:#CCCCCC;color: #ffffff;height: 20px; line-height: 20px;">' .
                self::$task_levels[$value] . '</div>';
        } elseif ($value == '2') {
            $str = '<div style = "background-color:#EEEE00;color: #ffffff;height: 20px; line-height: 20px;">' .
                self::$task_levels[$value] . '</div>';
        } elseif ($value == '3') {
            $str = '<div style = "background-color:#ff1200;color: #ffffff;height: 20px; line-height: 20px;">' .
                self::$task_levels[$value] . '</div>';
        }
        return $str;
    }

    /**
     * 任务状态
     *
     * @param $value
     *
     * @return string
     *
     * create by zqk 20180925
     */
    private function getStatus($value)
    {
        $str = '';
        if ($value == '1') {
            $str = '<div style = "background-color:#CCCCCC;color: #ffffff;height: 20px; line-height: 20px;">' .
                self::$task_status[$value] . '</div>';
        } elseif ($value == '2') {
            $str = '<div style = "background-color:#6495ED;color: #ffffff;height: 20px; line-height: 20px;">' .
                self::$task_status[$value] . '</div>';
        } elseif ($value == '3') {
            $str = '<div style = "background-color:#66CDAA;color: #ffffff;height: 20px; line-height: 20px;">' .
                self::$task_status[$value] . '</div>';
        } elseif ($value == '4') {
            $str = '<div style = "background-color:#ee0146;color: #ffffff;height: 20px; line-height: 20px;">' .
                self::$task_status[$value] . '</div>';
        }
        return $str;
    }

    /**
     * 任务是否审核
     *
     * @param $value
     *
     * @return string
     *
     * create by zqk 20180925
     */
    private function getChecked($value)
    {
        $str = '';
        if ($value != 1) {
            $str = '<div style = "background-color:#ff1b00;color: #ffffff;height: 20px; line-height: 20px;">' .
                '未审核' . '</div>';
        } elseif ($value == 1) {
            $str = '<div style = "background-color:#0079c8;color: #ffffff;height: 20px; line-height: 20px;">' .
                '已审核' . '</div>';
        }
        return $str;
    }

}

